<?php
require PATH_CONTROLLERS . 'BaseController.php';
class NewsController extends BaseController {

    /**
     * 初始化模块名
     */
    function _run() {
        parent::$module = isset($_GET['M']) ? strtolower(trim($_GET['M'])) : 'news';
        parent::$class = isset($_GET['C']) ? strtolower(trim($_GET['C'])) : '';
        parent::$action = isset($_GET['A']) ? strtolower(trim($_GET['A'])) : '';
    }
    
    /**
     * 引入视图页
     * @param string $file_name 文件名称不含后缀
     * @return type
     */
    static protected function display($file_name = '') {
        if (empty($file_name)) {
            $file_name = parent::$class;
        }
        return PATH_VIEWS . parent::$module . '/' . $file_name . '.php';
    }
    
    /**
      +--------------------------------------------------------------------------
     *  载入指定的模型层
      +--------------------------------------------------------------------------
     * @param string $model_name 模型层主类名
     * @return object
     */
    static protected function loadModelClass($model_name = '') {
        $model_name = !empty($model_name) ? (ucfirst($model_name) . 'Model') : (ucfirst(parent::$class) . 'Model');
        require_once PATH_MODELS . parent::$module . "/$model_name.class.php";
        return new $model_name();
    }

}
